| Total Complexity | 2 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {Inject} from '@nestjs/common'; |
||
| 8 | |||
| 9 | @QueryHandler(GetCustomersQuery) |
||
| 10 | export class GetCustomersQueryHandler { |
||
| 11 | constructor( |
||
| 12 | @Inject('ICustomerRepository') |
||
| 13 | private readonly customerRepository: ICustomerRepository |
||
| 14 | ) {} |
||
| 15 | |||
| 16 | public async execute( |
||
| 17 | query: GetCustomersQuery |
||
| 18 | ): Promise<Pagination<CustomerView>> { |
||
| 19 | const customerViews: CustomerView[] = []; |
||
| 20 | const [customers, total] = await this.customerRepository.findCustomers( |
||
| 21 | query.page |
||
| 22 | ); |
||
| 23 | |||
| 24 | for (const customer of customers) { |
||
| 25 | const address = customer.getAddress(); |
||
| 26 | |||
| 27 | customerViews.push( |
||
| 28 | new CustomerView( |
||
| 29 | customer.getId(), |
||
| 30 | customer.getName(), |
||
| 31 | new AddressView( |
||
| 32 | address.getId(), |
||
| 33 | address.getStreet(), |
||
| 34 | address.getCity(), |
||
| 35 | address.getZipCode(), |
||
| 36 | address.getCountry() |
||
| 37 | ) |
||
| 38 | ) |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | return new Pagination<CustomerView>(customerViews, total); |
||
| 43 | } |
||
| 45 |